const initState = {
  count: 10,
};

export const setCount = (payload) => {
  // 异步action, 允许返回一个函数,使用dispatch派发action
  return (dispatch) => {
    setTimeout(() => {
      dispatch({
        type: "SET_COUNT",
        payload,
      });
    }, 1000);
  };
};

export default (state = initState, action) => {
  let { type, payload } = action;
  switch (type) {
    case "SET_COUNT":
      return {
        ...state,
        count: payload,
      };

    default:
      return state;
  }
};
